package cn.biplam.back.bean.sqlengine.function;

import cn.biplam.common.paramters.DatabaseType.DataBase_Type;
import cn.biplam.common.paramters.SelectConstant.Function;
import cn.biplam.common.wrapper.Date;
import cn.biplam.common.wrapper.ErrorMessage;

public class FunctionFactory {
	
	public String getFunction(String dbType,Function function) throws ErrorMessage{
		if(DataBase_Type.Oracle.toString().equals(dbType)){
			return getFunctionOracle(function);
		}else if(DataBase_Type.Derby.toString().equals(dbType)){
			return getFunctionDerby(function);
		}else{
			throw new ErrorMessage("dbType is not found:"+dbType);
		}
	}
	
	public String getFunctionDerby(Function function) throws ErrorMessage{
		if(Function.SYSDATE.equals(function)){
			return "Date('"+new Date().getDateTime()+"')";
		}else{
			throw new ErrorMessage("function is not found:"+function);
		}
	}
	
	public String getFunctionOracle(Function function) throws ErrorMessage{
		if(Function.SYSDATE.equals(function)){
			return "sysdate";
		}else{
			throw new ErrorMessage("function is not found:"+function);
		}
	}
}
